// Metgine/Graphics/ParticleSystem.h
//
// Copyright 2011 Phillip Stephens
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// Linking this library statically or dynamically with other modules is
// making a combined work based on this library.  Thus, the terms and
// conditions of the GNU General Public License cover the whole
// combination.

#ifndef __PARTICLESYSTEM_H__
#define __PARTICLESYSTEM_H__

#include <Metgine/Graphics/FXManager.h>
#include <Metgine/Graphics/Particle.h>
#include <Metgine/Core/Vector2.h>

using namespace Metgine::Core;

namespace Metgine
{
namespace Graphics
{

class ParticleSystem : public Effect
{
public:

    // Constructor
    ParticleSystem(ImageResource* imageResource, float life, float gravity = 1.0f, float wind = 1.0f);

    // Destructor
    ~ParticleSystem();

    // Updates the particle system
    virtual void Update(float elapsedTime);

    // Renders the particle system
    virtual void Render(sf::RenderWindow& renderer);

    // Sets the life of the system
    virtual void SetLife(float life);

    // Gets the wind force being inflicted on the system
    virtual const float GetWind() const;

    // Sets the wind force being inflicted on the system
    virtual void SetWind(float);

    // Gets the gravity force being inflicted on the system
    virtual const float GetGravity() const;

    // Sets the gravity force being inflicted on the system
    virtual void SetGravity(float);

    // Emits a particle
    virtual void Emit(Particle* particle);

    // Updates a particle
    virtual void UpdateParticle(Particle* particle, float elapsedTime);

    // Gets the current number of particles active in the system
    virtual int GetNumParticles() const;

    // Returns true if the particle system should be rendered
    virtual bool IsAlive() const;

protected:

    ImageResource*               m_imageResource;
    std::vector<Particle>        m_particles;
    float                        m_spawnTimer;
    float                        m_spawnTime;
    Vector2f                     m_gravity;
    sf::Uint32                   m_numParticles;

};

}; // Graphics
}; // Metgine


#endif
